<?php
$id=$_GET['id'];
$connect=mysql_connect("localhost","root","192510");
mysql_select_db("news",$connect);
$sql="select * from shouzhong where id='{$id}'";
$result = mysql_query($sql);
$row=mysql_fetch_array($result);
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<link href="css/style.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="js/jquery-1.6.3.min.js"></script>
</head>

<body>

	<div class="place">
    <span>位置：</span>
    <ul class="placeul">
    <li><a href="#">受众列表</a></li>
	
	  <?php
		if($id==null){
	  ?>
		<li><a href="#">添加受众</a></li>
							 
	 <?php	 
		}else{
	 ?>
					
	    <li><a href="#">编辑受众</a></li>
	<?php
		}
	?>
	
    </ul>
    </div>
	
    <div class="formbody">
    <div class="formtitle"><span>基本信息</span></div>
	<form method="post" action="insert_shouzhong_commit.php">
	<input size="20" type="hidden" name="id" value="<?php echo $row['id'];?>">
    <ul class="forminfo">
    <li><label>名称</label><input  id="name" name="name" type="text" value="<?php echo $row['name'];?>"  onblur="shouzhong_name();" class="dfinput" /><i id="yz_name" style="display:none">名称不能为空</i></li>
    <li><label>类型</label><select class="dfinput" name="type" id="type"><option value="0"  <?php echo (isset($row)&&($row['type']==0))?'selected=selected':'';?>  onclick="user();">用户</option><option value="1"  <?php echo (isset($row)&&($row['type']==1))?'selected=selected':'';?> onclick="jiqi();">机器</option></select></li>
    <li id="yx"><label>邮箱</label><input id="email" name="email" onblur="yz_email();" type="text" value="<?php echo $row['email'];?>" class="dfinput"/><i id="yz_email_name" style="display:none">邮箱格式不符合规格</i></li>
	<li id="lic" style="display:none"><label>licesneID</label><input id="licesneID" name="licesneID" value="<?php echo $row['licesneID'];?>" type="text" class="dfinput"/></li>
	<li id="bz" style="display:none"><label>备注</label><textarea id="beizhu" name="beizhu" cols="" rows="" class="textinput"><?php echo $row['beizhu'];?></textarea></li>
    <li><label>&nbsp;</label><input name="" type="submit" class="btn" value="确认保存" onclick="return tijiao();"/></li>
    </ul>
	</form>
    </div>
</body>
</html>

<script>
    $(document).ready(function(){
		 var type=$("#type").val();
		   if(type==0){
			   $("#yx").show();
		       $("#lic").hide();
		       $("#bz").hide();
			   
		   }else{
			   $("#yx").hide();
		       $("#lic").show();
		       $("#bz").show();
		   }
		   
	})
		  
      function yz_email(){
		  //得到输入的值
		     var email=$("#email").val();
		     var reg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
			 
			 if(!reg.test(email)){
				 $("#yz_email_name").show();
			 }else{
				 
				 $("#yz_email_name").hide();
			 }
	   }
		  
   function jiqi(){
	   
		$("#lic").show();
		$("#bz").show();
		$("#yx").hide();
		
   }

   function user(){
	   
	   $("#yx").show();
	   $("#lic").hide();
	   $("#bz").hide();
	   
   }

   function shouzhong_name(){
	    var name=$("#name").val();
		  if(name==null||name.length==0){
			  $("#yz_name").show();
			  
		  }else{
			  $("#yz_name").hide();
		  }
		
   }
   
		function tijiao(){
		    var name=$("#name").val();
			if(name==null||name.length==0){
				alert("受众的名称不能为空");
				return false;
			}
			
			var email=$("#email").val();
			
			var reg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
			if(email==null||email.length==0){
			
			}else{
				
				 if(!reg.test(email)){//说明输入是错误的,无法提交
					 alert("请输入正确的邮箱格式");
					 return false;
			   } 
				
			}
			
			return true;
			
	   }
	   
</script>




